package show.me.the.money.resource;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;

public abstract class ResourceFile {
	static Properties oContentTypes = new Properties();
	String fileName;
	long lastModi;
	String postFix = "";
	boolean exists;
	
	public static void setContentTypeMapping(String name,String type){
		oContentTypes.put(name, type);
	}
	
	public static String getContentTypeMapping(String name){
		return oContentTypes.getProperty(name);
	}
	
	public static void loadContentTypeMappingFile(String fileName) throws IOException{
		   InputStream in = new BufferedInputStream(new FileInputStream(fileName));
	       oContentTypes.load(in);
	}
	
	public void setFileName(String fileName){
		this.fileName = fileName;
	}
	
	public boolean exists(){
		return exists;
	}
	
	public int length(){
		return 0;
	}
	
	public void setPostfix(String name){
		postFix = name;
	}
	
	public String getContentType(){
		if(oContentTypes.containsKey(postFix)){
			return oContentTypes.getProperty(postFix);
		}
		else{
			return "";
		}
	}
	public abstract InputStream getInputStream();	
	public abstract void load() throws IOException;
	public abstract void writeToStream(OutputStream outs,boolean needClose)throws IOException;
	public void writeToStream(OutputStream outs)throws IOException{
		writeToStream(outs,true);
	}
}
